import api from '../network/apis/api';
export default {
  namespaced: true,
  state: {
    productsData: {
      pageSize: 3, // 每页显示条数
      currentPage: 1, // 当前页
      totalPages: 1, // 总页数
      total: 0, // 总条数
      data: [],
    },
    searchData: {
      type: 'name',
      value: '',
    },
  },
  mutations: {
    setProdutsData(state, val) {
      state.productsData = val;
    },
    setSearchData(state, val) {
      state.searchData = val;
    },
    setTOPrevPage(state) {
      state.productsData.currentPage--;
    },
  },
  actions: {
    //获得保险产品
    async getAllProducts(context) {
      const { data } = await api.products.getALLProducts({
        type: context.state.searchData.type,
        value: context.state.searchData.value,
        currentPage: context.state.productsData.currentPage,
        pageSize: context.state.productsData.pageSize,
      });
      // console.log(data);
      if (data.status) {
        context.commit('setProdutsData', data.data);
      }
    },
  },
};
